import { getRoleListByPage } from '@/api/demo/system';
import { BasicColumn, FormSchema } from '@/components/Table';
import { useI18n } from '@/hooks/web/useI18n';

const { t } = useI18n();
/**
 * transform mock data
 * {
 *  0: '华东分部',
 * '0-0': '华东分部-研发部'
 * '0-1': '华东分部-市场部',
 *  ...
 * }
 */

export const deptMap = (() => {
  const pDept = ['华东分部', '华南分部', '西北分部'];
  const cDept = ['研发部', '市场部', '商务部', '财务部'];

  return pDept.reduce((map, p, pIdx) => {
    map[pIdx] = p;

    cDept.forEach((c, cIndex) => (map[`${pIdx}-${cIndex}`] = `${p}-${c}`));

    return map;
  }, {});
})();

export const columns: BasicColumn[] = [
  {
    title: t('sys.account.columns.username'),
    dataIndex: 'username',
    width: 120,
  },
  {
    title: t('sys.account.columns.password'),
    dataIndex: 'password',
    width: 120,
  },
  {
    title: t('sys.account.columns.status'),
    dataIndex: 'status',
    width: 120,
    customRender: ({ text }) => {
      return text ? t('sys.configuration.startUsing') : t('sys.configuration.forbidden');
    },
  },
  {
    title: t('sys.account.columns.roles'),
    dataIndex: 'roles',
    width: 120,
    customRender: ({ text }) => {
      if (Array.isArray(text)) {
        return text.map((record) => record.description).join(', ');
      }
      return '';
    },
  },
  // {
  //   title: '昵称',
  //   dataIndex: 'nickname',
  //   width: 120,
  // },

  // {
  //   title: t('sys.informaionMatchaing.columns.createTime'),
  //   dataIndex: 'createTime',
  //   width: 180,
  // },
  // {
  //   title: t('sys.account.columns.roles'),
  //   dataIndex: 'role',
  //   width: 200,
  // },
  {
    title: t('sys.device.columns.remck'),
    width: 120,
    dataIndex: 'remark',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'username',
    label: t('sys.account.columns.username'),
    component: 'Input',
    colProps: { xs: 24, sm: 12, md: 6, lg: 6, xl: 6 },
  },
];

export const accountFormSchema: FormSchema[] = [
  {
    field: 'username',
    label: t('sys.account.columns.username'),
    component: 'Input',
    helpMessage: [t('sys.account.columns.helpMessage')],
    required: true,
  },
  {
    field: 'password',
    label: t('sys.account.columns.password'),
    component: 'InputPassword',
    required: true,
  },
  {
    label: t('sys.account.columns.roles'),
    field: 'roleIds',
    component: 'ApiSelect',
    componentProps: {
      resultField: 'items', // 指定返回数据中的数组字段
      api: getRoleListByPage,
      labelField: 'description',
      valueField: 'roleId',
      mode: 'multiple', // 启用多选功能
    },
    required: true,
  },
  {
    label: t('sys.configuration.dataLimit'),
    field: 'maxFacebook',
    component: 'Input',
    required: true,
  },
  {
    label: t('sys.configuration.Unreadlimit'),
    field: 'maxNoRead',
    component: 'Input',
    required: true,
  },
  // {
  //   field: 'nickname',
  //   label: '昵称',
  //   component: 'Input',
  //   required: true,
  // },
  {
    label: t('sys.device.columns.remck'),
    field: 'remark',
    component: 'InputTextArea',
  },
];
